package com.pz.art.controller;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.pz.art.service.AnnualService;
import com.pz.art.domain.AssoAnnual;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 年度会费Controller
 *
 * @author ruoyi
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/system/annual")
public class AnnualController extends BaseController
{
    @Autowired
    private AnnualService assoAnnualService;

    /**
     * 查询年度会费列表
     */
    @PreAuthorize("@ss.hasPermi('system:annual:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssoAnnual assoAnnual)
    {
        startPage();
        List<AssoAnnual> list = assoAnnualService.selectAssoAnnualList(assoAnnual);
        return getDataTable(list);
    }

    /**
     * 导出年度会费列表
     */
    @PreAuthorize("@ss.hasPermi('system:annual:export')")
    @Log(title = "年度会费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssoAnnual assoAnnual)
    {
        List<AssoAnnual> list = assoAnnualService.selectAssoAnnualList(assoAnnual);
        ExcelUtil<AssoAnnual> util = new ExcelUtil<AssoAnnual>(AssoAnnual.class);
        util.exportExcel(response, list, "年度会费数据");
    }

    /**
     * 获取年度会费详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:annual:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assoAnnualService.selectAssoAnnualById(id));
    }

    /**
     * 新增年度会费
     */
    @PreAuthorize("@ss.hasPermi('system:annual:add')")
    @Log(title = "年度会费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssoAnnual assoAnnual)
    {
        return toAjax(assoAnnualService.insertAssoAnnual(assoAnnual));
    }

    /**
     * 修改年度会费
     */
    @PreAuthorize("@ss.hasPermi('system:annual:edit')")
    @Log(title = "年度会费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssoAnnual assoAnnual)
    {
        return toAjax(assoAnnualService.updateAssoAnnual(assoAnnual));
    }

    /**
     * 删除年度会费
     */
    @PreAuthorize("@ss.hasPermi('system:annual:remove')")
    @Log(title = "年度会费", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assoAnnualService.deleteAssoAnnualByIds(ids));
    }

    //获取单位总数和需缴纳总额
    @PreAuthorize("@ss.hasPermi('system:annual:getUnitTotal')")
    @GetMapping("/getUnitTotal")
    public AjaxResult getUnitTotal(){
        return success(assoAnnualService.getUnitTotal());
    }
}
